;$(function() {
	var id = $("#id").val();
	getInfo(id);
})

var cur={
    action:{

    },constant:{
        pageNo:1,
        pageSize:15,
    },constant2:{
        pageNo:1,
        pageSize:15,
    }
}

function d1(obj){
	$("#d1").show();
	$("#d2").hide();
    $("#d3").hide();
    var class_name=$("#presentation1").attr("class");
    if(class_name == 'undefined' || class_name == null || class_name == ''){
        $("#presentation1").addClass("active");
        $("#presentation2").removeClass("active");
        $("#presentation3").removeClass("active");
	}

    var id = $("#id").val();
    getInfo(id);
}

function d2(obj){
    var id = $("#id").val();
    getComment(id);
    $("#d1").hide();
    $("#d2").show();
    $("#d3").hide();
    var class_name=$("#presentation2").attr("class");
    if(class_name == 'undefined' || class_name == null || class_name == ''){
        $("#presentation2").addClass("active");
        $("#presentation1").removeClass("active");
        $("#presentation3").removeClass("active");
    }
}

function d3(obj){
    var id = $("#id").val();
    getPrise(id);
    $("#d1").hide();
    $("#d2").hide();
    $("#d3").show();
    var class_name=$("#presentation3").attr("class");
    if(class_name == 'undefined' || class_name == null || class_name == ''){
        $("#presentation3").addClass("active");
        $("#presentation1").removeClass("active");
        $("#presentation2").removeClass("active");
    }
}

function getInfo(id){
	   $.ajax({
        url: ctxPath+"/agency/workDynamic/findById/"+id,
        type: 'GET',
        success: function(d){
        	var success = d.success;
        	 if(success==true){
        	 var data=  d.data;
        	 if(data!=null){
        		 $("#deptName").html(data.deptName);
        		 $("#content").html(data.title);
        		 if(data.fileIds!=null){
           			 var img = "";
           			 var url=ctxPath+"/file/showImage/";
           			 for(var i=0;i<data.fileIds.length;i++){
           				 var temp = url+data.fileIds[i];
           				 img+='<li>'
             			+'<a href="'+temp+'" data-type="image">'
        				+'<img src="'+temp+'" alt="" width="100px;">'
        			    +'</a>'
        			    +'</li>'  ;
           			 }
           	    $("#dropzone").html(img);
           	 $('.plusview').plusview({
         		height : 400,
         		hide : "hide",
         		show : "show"
         	});
           	}	 
        	 }
        	}
        } 
    });
}


function getPrise(id){
    $.ajax({
        url: ctxPath+"/praise/getPage",
        type: 'POST',
        data: {pageNo:cur.constant2.pageNo,pageSize:cur.constant2.pageSize,"businessId":id},
        success: function(d){
            if(d.data!=null){
                var html="";
                $.each(d.data.dataList,function(i,item){
                    html+=toHtml2(item);
                })
                $("#list_result2").html(html);
            }
            getPage2(d.data.pages,d.data.total);
        }
    });
}

function getComment(id){
    $.ajax({
        url: ctxPath+"/comment/getPage",
        type: 'POST',
        data: {pageNo:cur.constant.pageNo,pageSize:cur.constant.pageSize,"businessId":id},
        success: function(d){
            if(d.data!=null){
                var html="";
                $.each(d.data.dataList,function(i,item){
                    html+=toHtml(item);
                })
                $("#list_result").html(html);
            }
            getPage(d.data.pages,d.data.total);
        }
    });
}

//分页
function getPage(pageCount,totalCount){
    kkpager.total =pageCount ;//总页码
    kkpager.totalRecords = totalCount;//总条数
    kkpager.generPageHtml({
        pno : 0,
        mode : 'click',//默认值是link，可选link或者click
        click : function(n){
            cur.constant.pageNo = n;
            getListPage();
            this.selectPage(n);
            return false;
        }
    });
}

function toHtml(data){

    var img = '/image/defualt.png';
    if (data.userFileId != null && data.userFileId != '') {
        img = ctxPath+'/file/showImage/' + data.userFileId;
    }

    var date = data.updateTime;
    if(date==null){
        date= data.createTime;
    }
    return '<tr>'
        +'<td>'
        + '<img src="' + img + '" width="100px;">&nbsp;&nbsp;&nbsp;&nbsp;' + data.userName
        +'</td>'
        +'<td>'
        +data.content
        +'</td>'
        +'<td>'
        +date
        +'</td>'
        +'<td>'
        +'<button type="button" class="btn btn-danger btn-sm waves-effect waves-light m-b-5" onclick="del(' + data.id + ')"><i class="fa fa-trash-o"></i> 删除</button>'
        +'</td>'
        +'</tr>';
}



function del(id){
    tale.alertConfirm({
        title:'确定删除吗?',
        then: function () {
            tale.post({
                url : ctxPath+'/comment/del',
                data: {id: id},
                success: function (result) {
                    if(result && result.success == true){
                        tale.alertOkAndReload('删除成功');
                        d2();
                    } else {
                        tale.alertError(result.msg || '删除失败');
                    }
                }
            });
        }
    });
}

//分页
function getPage2(pageCount,totalCount){
    kkpager2.total =pageCount ;//总页码
    kkpager2.totalRecords = totalCount;//总条数
    kkpager2.generPageHtml({
        pno : 0,
        mode : 'click',//默认值是link，可选link或者click
        click : function(n){
            cur.constant2.pageNo = n;
            getListPage();
            this.selectPage(n);
            return false;
        }
    });
}

function toHtml2(data){

    var img = '/image/defualt.png';
    if (data.userFileId != null && data.userFileId != '') {
        img = ctxPath+'/file/showImage/' + data.userFileId;
    }

    var date = data.updateTime;
    if(date==null){
        date= data.createTime;
    }
    return '<tr>'
        +'<td width="10%">'
        + '<img src="' + img + '" width="100px;">&nbsp;&nbsp;&nbsp;&nbsp;'
        +'</td>'
        +'<td>'
        + data.userName + '<br>'+date
        +'</td>'
        +'</tr>';
}
